<include file="public/layout" />
<body style="background-color: #FFF; overflow: auto;"> 
<div class="page">
  <div class="fixed-bar">
    <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
      <div class="subject">
        <h3>品牌详情</h3>
        <h5>品牌添加与管理</h5>
      </div>
    </div>
  </div>
    <!--表单数据-->
    <form method="post" id="addEditBrandForm" >
    <div class="ncap-form-default">
      <dl class="row">
        <dt class="tit">
          <label for="ac_name"><em>*</em>品牌名称</label>
        </dt>
        <dd class="opt">
          <input type="text" placeholder="名称" class="input-txt" id="brand_name" name="name" value="{$brand.name}">
		  <span class="err" id="err_name" style="color:#F00; display:none;"></span>
            <p class="notic"></p>
        </dd>
      </dl>
	  <dl class="row">
        <dt class="tit">
          <label for="ac_name">品牌网址</label>
        </dt>
        <dd class="opt">
          <input type="text" class="input-txt" name="url" value="{$brand.url}">
		  <span  class="err" id="err_url" style="color:#F00; display:none;"></span>                                                     
          <p class="notic"></p>
        </dd>
      </dl>      
	  <dl class="row">
        <dt class="tit" colspan="2">
          <label class="" for="s_sort">所属分类</label>
        </dt>
        <dd class="opt">
          <div id="gcategory">
           <select name="parent_cat_id" id="parent_id_1" onblur="get_category(this.value,'parent_id_2','0');"  onchange="get_category(this.value,'parent_id_2','0');" class="form-control" >
                <option value="0">请选择分类</option> 
                <foreach name="cat_list" item="v" >	                                                                                    
                    <option value="{$v[id]}"  <if condition="$v[id] eq $brand[parent_cat_id]"> selected="selected" </if>>{$v[name]}</option>
                </foreach>                                            
            </select>
          <select name="cat_id" id="parent_id_2"  class="form-control" style="width:250px;">
            <option value="0">请选择分类</option>
          </select>
          </div>
        </dd>
      </dl>

      <dl class="row">
        <dt class="tit">
          <label>品牌logo</label>
        </dt>
        <dd class="opt">
          <div class="input-file-show">
              <span class="show">
                  <a id="img_a" target="_blank" class="nyroModal" rel="gal" href="{$brand.logo}">
                    <i id="img_i" class="fa fa-picture-o" onmouseover="layer.tips('<img src={$brand.logo}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();"></i>
                  </a>
              </span>
              <span class="type-file-box">
                  <input type="text" id="logo" name="logo" value="{$brand.logo}" class="type-file-text">
                  <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                  <input class="type-file-file" onClick="GetUploadify(1,'','brand','img_call_back')" size="30" hidefocus="true" nc_type="change_site_logo"
                         title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
              </span>
          </div>
          <span class="err"></span>
          <p class="notic">请上传图片格式文件</p>
        </dd>
      </dl>
                 		 		       
      <dl class="row">
        <dt class="tit">
          <label for="ac_sort">排序</label>
        </dt>
        <dd class="opt">
          <input type="text" placeholder="排序" name="sort" value="{$brand.sort}" maxlength="3" class="input-txt">
          <span class="err" id="err_sort" style="color:#F00; display:none;"></span>
            <p class="notic"></p>
        </dd>
      </dl>
	  <dl class="row">
        <dt class="tit">
          <label for="ac_sort">品牌描述</label>
        </dt>
        <dd class="opt">
          
          <textarea rows="4" cols="60" name="desc" class="input-txt">{$brand.desc}</textarea>
          <span class="err" id="err_desc" style="color:#F00; display:none;"></span>                
          <p class="notic"></p>
        </dd>
      </dl>	
                              
      <div class="bot"><a href="JavaScript:void(0);" onClick="verifyForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a></div>
    </div>
        <input type="hidden" name="id" value="{$brand.id}">
        <input type="hidden" name="p" value="{$_GET[p]}">   
  </form>
</div>
<script>
function verifyForm(){
    var name = $("#brand_name").val();
    var cat_id = $("#parent_id_2").val();
    if($.trim(name) == '') {
        layer.msg('请输入名称！！', {icon: 2});return false;
    }

    if(cat_id == 0) {
        layer.msg('所属分类必须选择第二级！！', {icon: 2});return false;
    }
    $('span.err').show();
    $.ajax({
        type: "POST",
        url: "{:U('Admin/Goods/addEditBrand')}",
        data: $('#addEditBrandForm').serialize(),
        dataType: "json",
        error: function () {
            layer.alert("服务器繁忙, 请联系管理员!");
        },
        success: function (data) {
            if (data.status == 1) {
                layer.msg(data.msg, {icon: 1},function () {
                    location.href = "{:U('Admin/Goods/brandList')}";
                });
            } else {
                layer.msg(data.msg, {icon: 2});
                $.each(data.result, function (index, item) {
                    $('#err_' + index).text(item).show();
                });
            }
        }
    });
}


window.onload = function(){
    var brand_cat_id = parseInt('{$brand.cat_id}');
	if(brand_cat_id > 0 ){
		get_category($("#parent_id_1").val(),'parent_id_2',brand_cat_id);	 
	}		
}
function img_call_back(fileurl_tmp)
{
  $("#logo").val(fileurl_tmp);
  $("#img_a").attr('href', fileurl_tmp);
  $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
}
</script>
</body>
</html>